﻿using MovingChameLibrary.Models;
using MovingChameLibrary.Models.Action;
using MovingChameLibrary.ViewModels;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace MovingChameLibrary.DataManager
{
    public class UserFriendData
    {
        private static UserFriendData current;
        public static UserFriendData Current
        {
            get
            {
                if (current == null)
                    current = new UserFriendData();
                return current;
            }
        }

        private ObservableCollection<FriendGroup> _allGroups;
        public ObservableCollection<FriendGroup> AllGroups
        {
            get
            {
                _allGroups = new ObservableCollection<FriendGroup>();
                _allGroups.Add(UserFriendData.Current.AddedGroup);
                _allGroups.Add(UserFriendData.Current.RequestGroup);
                _allGroups.Add(UserFriendData.Current.ReceivingGroup);
                return _allGroups;
            }
        }

        private FriendGroup _addedGroup;
        public FriendGroup AddedGroup
        {
            get
            {
                if (_addedGroup == null)
                {
                    _addedGroup = new FriendGroup(Constants.AddedFriendId, Constants.AddedFriendTitle);
                    _addedGroup.Items.Add(new AddNewFriend());
                }
                return this._addedGroup;
            }
        }

        private FriendGroup _requestGroup;
        public FriendGroup RequestGroup
        {
            get
            {
                if (_requestGroup == null)
                    _requestGroup = new FriendGroup(Constants.RequestFriendId, Constants.RequestFriendTitle);
                return this._requestGroup;
            }
        }

        private FriendGroup _receivingGroup;
        public FriendGroup ReceivingGroup
        {
            get
            {
                if (_receivingGroup == null)
                    _receivingGroup = new FriendGroup(Constants.ReceivingFriendId, Constants.ReceivingFriendTitle);
                return this._receivingGroup;
            }
        }

        public static FriendGroup GetItem(int uniqueId)
        {
            var matches = UserFriendData.Current.AllGroups.Where(item => (item as FriendGroup).Id.Equals(uniqueId));
            if (matches.Count() == 1) return matches.First();
            return default(FriendGroup);
        }
    }
}